package org.geektimes.configuration.micro.config.source;

import org.eclipse.microprofile.config.spi.ConfigSource;
import org.eclipse.microprofile.config.spi.ConfigSourceProvider;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ServiceLoader;

/**
 *
 */
public class DefaultConfigSourceProvider implements ConfigSourceProvider {
    @Override
    public Iterable<ConfigSource> getConfigSources(ClassLoader forClassLoader) {
        ServiceLoader<ConfigSource> load = ServiceLoader.load(ConfigSource.class, forClassLoader);
        Iterator<ConfigSource> iterator = load.iterator();
        List<ConfigSource> configSourceList = new LinkedList<>();;
        while (iterator.hasNext()){
            configSourceList.add(iterator.next());
        }
        return  configSourceList;
    }
}
